import java.util.StringTokenizer;



public class ScratchBoard {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		test1();
		
		String str1 = "my string";
		test2(str1);
		System.out.println("input string: " + str1);
		
	}

	private static void test2(String str) {
		str = str + " - new string";
	}
	
	private static void testCamalCase() {
		String source = "AGE";
		String result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);
		
		source = "FIRST_NAME";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);

		source = "first__NAME";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);
		
		source = "FIRST___NAME";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);

		source = "FIRST___N_A_M_E";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);

		source = "my_FIRST_NAME";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);
		
		source = "FIRST_NAME_";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);
		
		source = "_FIRST_NAME_";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);

		source = "ADDRESS1";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);
		
		source = "ADDRESS1_DETAIL";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);

		source = "ADDRESS_1";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);

		source = "    ";
		result = convertToCamelCase(source);
		System.out.println("source: " + source + ", result: " + result);
	}
	
	private static String convertToCamelCase(String source)
	{
		if (source == null || source.trim().length() == 0)
			return null;
		
		StringBuffer buf = new StringBuffer();
			
		for (int i = 0; i < source.length(); i++)
		{
			if (source.charAt(i) == '_')
			{
				if (i == 0)
					continue;
				
				if ((i+1) < source.length())
				{
					if (source.charAt(i+1) == '_')
						continue;
					else
						buf.append(source.toUpperCase().charAt(i+1));
				}
				i++;
			}
			else
			{
				buf.append(source.toLowerCase().charAt(i));
			}
		}
		
		return buf.toString();
	}
	
	private static void test1() {
		String input = "mystring";
		StringTokenizer st = new StringTokenizer(input, "q");
		while (st.hasMoreTokens()) {
			System.out.println("token: " + st.nextToken());
		}
	}
	
}
